package com.eningqu.aipen.ui.login;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.Intent;

import com.airbnb.lottie.LottieAnimationView;
import com.eningqu.aipen.demo.R;
import com.eningqu.aipen.demo.databinding.ActivitySplashBinding;
import com.eningqu.aipen.ui.MainActivity;
import com.eningqu.aipen.ui.base.BaseActivity;
import com.eningqu.aipen.utils.GlobalConfig;
import com.eningqu.aipen.utils.SPUtil;

/**
 * Package:com.eningqu.aipen.ui.login
 * Author:starr
 * Time:2023/9/14  11:01
 * Description:
 */
public class SplashActivity extends BaseActivity<ActivitySplashBinding> {

    private LottieAnimationView mLottieView;

    private String userName;
    private String userPassword;

    public static void startAction(Context context) {
        Intent intent = new Intent(context, SplashActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initView() {
        mLottieView = mBinding.splashLottie;
        mLottieView.addAnimatorListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mLottieView.removeAnimatorListener(this);
                if ("".equals(userName) || "".equals(userPassword)) {
                    LoginActivity.startAction(getContext());
                } else {
                    MainActivity.startAction(getContext());
                }
                finish();
            }
        });
    }

    @Override
    protected void initData() {
        //如果本地有缓存密码和账户就直接读取
        userName = (String) SPUtil.getInstance().getData(GlobalConfig.user_Phone, "");
        userPassword = (String) SPUtil.getInstance().getData(GlobalConfig.user_Password, "");
    }

    @Override
    protected void initActivity() {
        super.initActivity();
    }

    @Override
    protected void async() {

    }
}
